package com.wxapp.common.base.knife4j;

import com.wxapp.common.constant.properties.SwaggerProperties;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
public class Knife4jConfiguration {
    public final SwaggerProperties swaggerProperties;

    @Bean
    public OpenAPI springShopOpenAPI() {
        return new OpenAPI()
                .info(new Info().title(swaggerProperties.getTitle())
                        .description(swaggerProperties.getDescription())
                        .version(swaggerProperties.getVersion()));
    }

    @Bean
    public GroupedOpenApi serviceApi() {
        return GroupedOpenApi.builder().group("service").packagesToScan(swaggerProperties.getServicePackage())
                .packagesToExclude(swaggerProperties.getClientPackage())
                .build();
    }

    @Bean
    public GroupedOpenApi ClientApi() {
        return GroupedOpenApi.builder().group("client").packagesToScan(swaggerProperties.getClientPackage()).build();
    }
}